package demo4;

import java.sql.Array;
import java.util.Arrays;

class Student implements Comparable<Student>{
    String name;
    int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

//    @Override
//    public int compareTo(Student o) {
//        if(this.name.compareTo(o.name)>0){
//            return 1;
//        } else if (this.name.compareTo(o.name)==0) {
//            return 0;
//        }else {
//            return -1;
//        }
//    }

    @Override
    public int compareTo(Student o) {
        if(this.age>o.age){
            return 1;
        }else if(this.age==o.age){
            return 0;
        }else{
            return -1;
        }

    }

}
public class Text {
    public static void mysort(Comparable[] comparable){
        for(int i=0;i<comparable.length-1;i++){
            for (int j=0;j<comparable.length-1-i;j++){
                if(comparable[j].compareTo(comparable[j+1])>0){
                    Comparable tmp=comparable [j];
                    comparable[j]=comparable[j+1];
                    comparable[j+1]=tmp;
                }
            }
        }
    }
    public static void main(String[] args) {
        Student[]students=new Student[3];
        students[0]=new Student("zhangsan",12);
        students[1]=new Student("lisi",8);
        students[2]=new Student("wamgwu",10);
        System.out.println(Arrays.toString(students));
        mysort(students);
       // Arrays.sort(students);
        System.out.println(Arrays.toString(students));

    }
//    public static void main1(String[] args) {
//        Student student1=new Student("zhangsan",12);
//        Student student2=new Student("lisi",10);
//        if(student1.compareTo(student2)>0){
//            System.out.println("student1>student2");
//        }else{
//            System.out.println("student1<=student2");
//
//        }
//    }
}
